home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / highlight / highlight-W32GUI-2.2-10b-Setup.exe / {app} / src / configurationreader.cpp < prev    next >
C/C++ Source or Header  |  2005-03-20  |  3KB  |  81 lines

  1. /***************************************************************************
  2.                           configurationreader.cpp  -  description
  3.                              -------------------
  4.     begin                : Son Nov 10 2002
  5.     copyright            : (C) 2002 by AndrΘ Simon
  6.     email                : andre.simon1@gmx.de
  7.  ***************************************************************************/
  8.  
  9. /***************************************************************************
  10.  *                                                                         *
  11.  *   This program is free software; you can redistribute it and/or modify  *
  12.  *   it under the terms of the GNU General Public License as published by  *
  13.  *   the Free Software Foundation; either version 2 of the License, or     *
  14.  *   (at your option) any later version.                                   *
  15.  *                                                                         *
  16.  ***************************************************************************/
  17.  
  18. #include "configurationreader.h"
  19.  
  20. using namespace std;
  21.  
  22. ConfigurationReader::ConfigurationReader(const string & configuration_path)
  23. {
  24.   ifstream in (configuration_path.c_str());
  25.   fileFound=in;
  26.   if (fileFound) {
  27.     string line;
  28.     line.reserve(500);
  29.     unsigned int  lineBegin;
  30.     size_t delimPos;
  31.     string paramName, paramValue;
  32.     while (getline(in, line)) {
  33.       lineBegin=line.find_first_not_of("\t ");
  34.       if ((line.size()>2) && (lineBegin!=string::npos)
  35.             && (line.at(lineBegin)!='#')) {  //comment?
  36.           if (line[lineBegin]=='$') {       // neuer Parametername?
  37.              delimPos=line.find("=",lineBegin)-1;
  38.              if (delimPos!=string::npos) {
  39.                  paramName=StringTools::trimRight(
  40.                            StringTools::lowerCase(line.substr(lineBegin+1, delimPos)));
  41.                  parameterNames.push_back(paramName);
  42.                  paramValue=line.substr(delimPos+2, line.length());
  43.               }
  44.             } else  { // line belongs to last parameter
  45.                 paramValue=line;
  46.             }
  47.             if (parameterMap[paramName].empty())  {
  48.                parameterMap[paramName] = paramValue;
  49.             } else {
  50.                 parameterMap[paramName]+= (" "+paramValue);
  51.             }
  52.          }  //if ((lineBegin!=string::npos) && (line.at(lineBegin)!='#'))
  53.       } //while
  54.     in.close();
  55.   } //if (in)
  56. }
  57.  
  58. ConfigurationReader::~ConfigurationReader()
  59. {
  60. }
  61.  
  62. bool ConfigurationReader::found()
  63. {
  64.   return fileFound;
  65. }
  66.  
  67. string &ConfigurationReader::getParameter(const string & paramName)
  68. {
  69.   return parameterMap[paramName] ;
  70. }
  71.  
  72. const char* ConfigurationReader::getCParameter(const string & paramName)
  73. {
  74.   return parameterMap[paramName].c_str() ;
  75. }
  76.  
  77. vector<string> &ConfigurationReader::getParameterNames()
  78. {
  79.   return parameterNames;
  80. }
  81.